package com.alibaba.citrus.ots.price.ability.functions.factory.activity;

import com.alibaba.citrus.ots.common.util.SpringContextUtil;
import com.alibaba.citrus.ots.price.ability.functions.entity.activity.SegmentedActivityCombinationEntity;
import com.alibaba.citrus.ots.price.ability.functions.entity.activity.SegmentedActivityTermEntity;
import com.alibaba.citrus.ots.price.repository.ActivityQueryRepository;
import com.epoch.app.otspricecenter.dto.request.SegmentedDetailQueryViewRequest;
import com.epoch.app.otspricecenter.sdo.SegmentedActivityTermSDO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author hanguo
 * @date 2021/10/18
 * @Description 坎级活动工厂
 */
public class SegmentedActivityTermFactory {

    private static ActivityQueryRepository queryRepository = SpringContextUtil.getBean(ActivityQueryRepository.class);

    /**
     * 创建活动抬头实体列表
     *
     * @param request
     * @return
     */
    public static SegmentedActivityTermEntity create(SegmentedDetailQueryViewRequest request) {
        SegmentedActivityTermSDO segmentedActivityTermSDO = new SegmentedActivityTermSDO();
        BeanUtils.copyProperties(request, segmentedActivityTermSDO);
        return SegmentedActivityTermEntity.of(segmentedActivityTermSDO);
    }

    /**
     * 根据活动 id 和 活动项目 id 查询坎级活动列表
     *
     * @param activityId     活动 id
     * @param activityTermId 活动项目 id
     * @return
     */
    public static List<SegmentedActivityTermEntity> create(String activityId, String activityTermId) {
        List<SegmentedActivityTermEntity> result = new ArrayList<>();
        //根据活动 id,活动项目 id ，查询坎级活动表
        List<SegmentedActivityTermSDO> sdoList = queryRepository.querySegmentedActivityTermList(activityId, activityTermId);

        if (Objects.nonNull(sdoList) && CollectionUtils.isNotEmpty(sdoList)) {
            //对每一个坎级活动补全坎级活动组合信息列表
            sdoList.forEach(sdo -> {
                SegmentedActivityTermEntity termEntity = SegmentedActivityTermEntity.of(sdo);
//                List<SegmentedActivityCombinationEntity> combinationEntityList =
//                        SegmentedActivityCombinationFactory.create(activityId, activityTermId, sdo.getSegmentedActivityId());
//                termEntity.setCombinationEntityList(combinationEntityList);
                result.add(termEntity);
            });
        }

        return result;
    }
}
